import { defineConfig, loadEnv } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import Unocss from 'unocss/vite';
import Components from '@uni-helper/vite-plugin-uni-components';
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers';
import { resolve } from 'path';

// https://vitejs.dev/config/
export default ({ mode }: { mode: string }) => {
  const env = loadEnv(mode, process.cwd());
  const publicPath = env.VITE_PUBLIC_PATH ?? '/';

  return defineConfig({
    plugins: [
      Components({
        resolvers: [WotResolver()],
        dts: './types/components.d.ts',
      }),
      uni(),
      Unocss(),
    ],
    base: publicPath,
    server: {
      port: 3002,
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        '#': resolve(__dirname, './types'),
      },
    },
  });
};
